<template>
  <div class="item">
    <div class="content">
      <div class="item_left">
        <div class="title">{{ props.item.title }}</div>
        <div class="des">{{ props.item.rules }}</div>
        <div class="price">￥{{ props.item.payValue/100 }}</div>
      </div>
      <div class="item_right">
        <el-button type="danger" round @click="voucherHandle">抢购</el-button>
        <div v-if="!(props.item.stock === -1)" class="surplus">剩余：{{ props.item.stock }}</div>
        <div class="timeLimit">{{ props.item.beginTime }}~{{ props.item.endTime }} </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from 'vue'
import {payVoucher} from "@/apis/voucher.js";
import {ElMessage} from "element-plus";

const props = defineProps({
  item: Object
})

const voucherHandle = async () => {
  payVoucher(props.item.id).then((res) => {
    ElMessage.success(res.msg)
  })
}

</script>

<style scoped>
.item{
  height: 15vh;
  width: 65.5vh;
  background-color: #fff;
  border-radius: 8px;
  margin: 3vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.content{
  height: 13vh;
  width: 63vh;
  background-color: #fcd3d3;
  display: flex;
}
.item_left{
  height: 100%;
  width: 55%;
  display: flex;
  align-items: center;
  flex-direction: column;
}
.item_right{
  height: 100%;
  width: 45%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.title{
  font-size: 18px;
  font-weight: bold;
}
.des{
  font-size: 14px;
  color: #73767a;
}
.price{
  font-size: 20px;
  color: #F56C6C;
  font-weight: bold;
}
.surplus{
  font-size: 12px;
  color: #73767a;
}
.timeLimit{
  font-size: 14px;
  color: #F56C6C;
}

</style>
